<template>
  <div class="app-container">
    <el-alert
      title="全选:删除,添加分类,暂未研发"
      type="info" style="margin-bottom: 10px">
    </el-alert>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>文章列表</span>
        <!--        <el-button style="float: right; padding: 3px 0" type="text">操作按钮</el-button>-->
      </div>
      <el-table
        :data="list.filter(data => !search || data.Title.toLowerCase().includes(search.toLowerCase()))"
        style="width: 100%">
        <el-table-column
          label="Id"
          width="80">
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{ scope.row.Id }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="图片"
          width="180">
          <template slot-scope="scope">
            <img :src="scope.row.Img" alt="" width="100px">
          </template>
        </el-table-column>
        <el-table-column
          label="标题"
          width="180">
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{ scope.row.Title }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="关联标签"
          width="180">
          <template slot-scope="scope">
            <el-tag v-for="item in scope.row.Tag" :key="item.Id">{{ item.Title }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="分类"
          width="180">
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{scope.row.Nav[0] ? scope.row.Nav[0].Title :''}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="创建时间"
          width="180">
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{ scope.row.AddTime }}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="right">
          <template slot="header" slot-scope="scope">
            <el-input
              v-model="search"
              size="mini"
              placeholder="输入关键字搜索"/>
          </template>
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleEdit(scope.$index, scope.row)">修改
            </el-button>
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>

import { getArticleList, delArticle } from '@/api/article'

export default {
  data() {
    return {
      list: [],
      search: ''
    }
  },
  created() {
    console.log(this.$router)
    this.getArticle()
  },
  methods: {
    // 显示文章列表
    getArticle() {
      getArticleList().then(con => {
        console.log(con)
        this.list = con.data
      })
    },
    // 修改文章
    handleEdit(index, row) {
      console.log(index, row);
    },
    // 删除文章
    handleDelete(index, row) {
      console.log(index, row);
      delArticle(row.Id).then(con => {
        console.log(con)
        if (con.code) {
          this.getArticle()
          this.$message({
            message: '删除成功',
            type: 'success'
          });
        } else {
          this.$message({
            message: '删除失败',
            type: 'error'
          });
        }

      })
    }
  }
}
</script>
